import http from '@/utils/http'

const BASE_URL = '/asset/consumable/records'

export interface ConsumableRecordsResp {
  id: string
  name: string
  categoryId: string
  categoryName: string
  size: string
  count: string
  price: string
  producerId: string
  producerName: string
  description: string
  createUser: string
  createTime: string
  updateUser: string
  updateTime: string
  createUserString: string
  updateUserString: string
  disabled: boolean
}
export interface ConsumableRecordsDetailResp {
  id: string
  name: string
  categoryId: string
  categoryName: string
  size: string
  count: string
  price: string
  producerId: string
  producerName: string
  description: string
  createUser: string
  createTime: string
  updateUser: string
  updateTime: string
  createUserString: string
  updateUserString: string
}
export interface ConsumableRecordsQuery {
  name: string | undefined
  categoryId: string | undefined
  count: string | undefined
  sort: Array<string>
}
export interface ConsumableRecordsPageQuery extends ConsumableRecordsQuery, PageQuery {}

/** @desc 查询耗材列表 */
export function listConsumableRecords(query: ConsumableRecordsPageQuery) {
  return http.get<PageRes<ConsumableRecordsResp[]>>(`${BASE_URL}`, query)
}

/** @desc 查询耗材详情 */
export function getConsumableRecords(id: string) {
  return http.get<ConsumableRecordsDetailResp>(`${BASE_URL}/${id}`)
}

/** @desc 新增耗材 */
export function addConsumableRecords(data: any) {
  return http.post(`${BASE_URL}`, data)
}

/** @desc 修改耗材 */
export function updateConsumableRecords(data: any, id: string) {
  return http.put(`${BASE_URL}/${id}`, data)
}

/** @desc 删除耗材 */
export function deleteConsumableRecords(id: string) {
  return http.del(BASE_URL, { ids: [id] })
}

/** @desc 导出耗材 */
export function exportConsumableRecords(query: ConsumableRecordsQuery) {
  return http.download(`${BASE_URL}/export`, query)
}

/** @desc 耗材入库 */
export function consumableInbound(data: any) {
  return http.post(`${BASE_URL}/inbound`, data)
}

/** @desc 耗材领用 */
export function consumableUsage(data: any) {
  return http.post(`${BASE_URL}/usage`, data)
}